package com.wanxi.dangdang.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public Queue leaveQueue() {
        return new Queue("LeaveQueue", true);
    }

    @Bean
    DirectExchange LeaveDirectExchange() {
        return new DirectExchange("LeaveDirectExchange", true, false);
    }

    @Bean
    FanoutExchange LeaveFanoutExchange() {
        return new FanoutExchange("LeaveFanoutExchange", true, false);
    }

    @Bean
    TopicExchange LeaveTopicExchange() {
        return new TopicExchange("LeaveTopicExchange", true, false);
    }

    @Bean
    Binding LeaveQueueToUserDirect() {
        return BindingBuilder.bind(leaveQueue()).to(LeaveDirectExchange()).with("Leave.queue");
    }

    @Bean
    Binding LeaveQueueToUserFanout() {
        return BindingBuilder.bind(leaveQueue()).to(LeaveFanoutExchange());
    }

    @Bean
    Binding LeaveQueueToUserTopic() {
        return BindingBuilder.bind(leaveQueue()).to(LeaveTopicExchange()).with("Leave.#");
    }
}